<!--
 * @Author: liqi
 * @Date: 2022-10-12 15:24:21
 * @LastEditors: liqi
 * @LastEditTime: 2022-10-15 13:27:48
 * @Description:
-->
<template>
  <!-- 账户变动审核 -->
  <div>
    <!-- 第一部分 表单内容 -->
    <div class="header">
      <el-form :inline="true" :model="form" class="demo-form-inline">
        <el-date-picker
          v-model="datePick"
          value-format="timestamp"
          type="datetimerange"
          :picker-options="pickerOptions"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          align="right"
          class="date-picker"
        />
        <el-form-item>
          <el-select
            v-model="form.applyType"
            placeholder="请选择类型"
            clearable
          >
            <el-option label="充值" value="充值" />
            <el-option label="体现" value="体现" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="form.status" placeholder="请选择状态" clearable>
            <el-option label="通过" value="通过" />
            <el-option label="未通过" value="未通过" />
            <el-option label="未审核" value="未审核" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="form.userId"
            placeholder="申请人编号"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSearch">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 第一部分结束 表单内容 -->
    <!-- 第二部分 表格数据 -->
    <el-table :data="tableData" style="width: 100%">
      <el-table-column align="center" type="index" label="序号" />
      <el-table-column align="center" prop="userId" label="申请人编号" />
      <el-table-column align="center" prop="applyTime" label="申请时间">
        <template slot-scope="scope">
          <span>{{ scope.row.applyTime | fmtDate1 }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="applyType" label="变更类型" />
      <el-table-column align="center" prop="money" label="变更资金">
        <template slot-scope="scope">
          <span>￥<span class="money">{{ scope.row.money }}</span>元</span>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="reason" label="变更原因" />
      <el-table-column align="center" prop="status" label="状态">
        <template slot-scope="scope">
          <el-tag
            v-if="scope.row.status === '通过'"
            type="success"
          >通过</el-tag>
          <el-tag
            v-else-if="scope.row.status === '不通过'"
            type="danger"
          >不通过</el-tag>
          <el-tag v-else type="info">未审核</el-tag>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <span v-if="scope.row.status === &quot;未审核&quot;">
            <a
              href="#"
              class="pass"
              @click.prevent="changeStatus(scope.row.id,'通过')"
            >通过</a>
            <a
              href="#"
              class="fail"
              @click.prevent="changeStatus(scope.row.id,'不通过')"
            >不通过</a>
          </span>

        </template>
      </el-table-column>
    </el-table>
    <!-- 第二部分结束 表格数据 -->
    <!-- 第三部分 分页按钮 -->
    <el-pagination
      :current-page="params.page"
      :page-sizes="[5, 6, 8, 10, 15, 20]"
      :page-size="params.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      class="page"
      align="right"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
    <!-- 第三部分结束 分页按钮 -->
  </div>
</template>

<script>
import { queryAccountApply, pass, fail } from '@/api/accountApply.js'
import { fmtDate1 } from '@/filters/index.js'
export default {
  data() {
    return {
      // 日期选择
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }
        ]
      },
      // 表单数据
      params: {
        page: 1,
        pageSize: 10
      },
      form: {},
      datePick: [],
      // 表格数据
      tableData: [],
      // 总条数
      total: 0
    }
  },
  computed: {},
  created() {
    this.getTableDate()
  },
  mounted() {},
  methods: {
    // 查询
    onSearch() {
      this.params.page = 1
      this.getTableDate()
    },
    // 通过/不通过
    async changeStatus(id, status) {
      if (status === '通过') {
        const res = await pass({ id })
        this.$message({
          message: res.message,
          type: 'success'
        })
      } else {
        const res = await fail({ id })
        this.$message({
          message: res.message,
          type: 'success'
        })
      }
      this.getTableDate()
    },
    // 获取表格数据
    async getTableDate() {
      const temp = { ...this.params, ...this.form }
      for (const key in temp) {
        if (!temp[key]) {
          delete temp[key]
        }
      }
      if (this.datePick) {
        temp.beginTime = this.datePick[0]
        temp.endTime = this.datePick[1]
      }
      const res = await queryAccountApply(temp)
      this.tableData = res.data.list
      this.total = res.data.total
    },
    handleSizeChange(pageSize) {
      this.params.pageSize = pageSize
      this.params.page = 1
      this.getTableDate()
    },
    handleCurrentChange(page) {
      this.params.page = page
      this.getTableDate()
    }
  }
}
</script>
<style scoped>
.date-picker {
  margin-right: 10px;
}
.money {
  color: #e65d6e;
  font-size: 18px;
  margin: 0 5px;
}
.pass {
  color: #3a71a8;
}
.fail {
  color: #e65d6e;
}
.page{
  margin-top: 10px;
}
</style>
